package com.example.helloworld;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;

import com.example.helloworld.persistence.UserInfo;
import com.example.helloworld.persistence.UserInfo.Role;

public class ParcelCallee extends Activity {

		private String getStatus(final UserInfo user) {
			final StringBuffer buf =	new StringBuffer();
			
			buf
				.append("user info - userId:[").append(user.getUserId()).append("]")
				.append(",userName:[").append(user.getUserName()).append("]")
				.append(",adminYn:[").append(user.isAdminYn()).append("]")
				.append("\n");
			
			final List<Role> list =	user.getRoleSet();
			
			for (int i = 0; i < list.size(); i++) {
				final Role role =	list.get(i);
				Log.i("role info - roleId, name, order", role.getRoleId() + "," + role.getName() + "," + role.getOrder());
				
				buf
				.append("role info - roleId:[").append(role.getRoleId()).append("]")
				.append(",name:[").append(role.getName()).append("]")
				.append(",order:[").append(role.getOrder()).append("]")
				.append("\n");
				
			}
			
			return buf.toString();
		}
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_parcel_callee);
		
		final Bundle bundle = 				getIntent().getExtras();
		final UserInfo user =				bundle.getParcelable("user");
		final ArrayList<UserInfo> list =	bundle.getParcelableArrayList("user.list");
		final StringBuffer buf =			new StringBuffer();
		
		buf.append("*** single user parcel ***").append('\n');
		buf.append(getStatus(user));
		buf.append("*** list user parcel ***").append('\n');
		for (int i = 0; i < list.size(); i++) {
			final UserInfo value =	list.get(i); 
			buf.append(getStatus(value));
		}
		
		final TextView text =	(TextView)findViewById(R.id.showStatus);
		text.setText(buf.toString());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.parcel_callee, menu);
		return true;
	}

}
